//
//  SettingViewModel.swift
//  TimMusic
//
//  Created by nkl on 2024/10/11.
//

import Foundation
import UIKit

class SettingViewModel: NSObject, UITableViewDataSource {
    var datas: [SettingViewCellViewModel] = []

    func requestDatas() {
        let models = SettingType.allCases.map {
            SettingViewCellViewModel(cellModel: SettingModel(type: $0))
        }
        datas = models
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        1
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        datas.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard  indexPath.row < datas.count else {
            return SettingViewCell<SettingModel>.init()
        }
        let cellData = datas[indexPath.row]
        let cell = tableView.dequeueReusableCell(withIdentifier: SettingViewCell<SettingModel>.cellIdentify, for: indexPath) as! SettingViewCell<SettingModel>
        cell.bindData(model: cellData.cellModel)
        return cell
    }
}
